//
//  InvestUnverifVC.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/14.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "InvestUnverifVC.h"
#import "InvestTableViewCell.h"
#import "InvestDetailHeadView.h"
#import "AgreeView.h"
#import "BankListVC.h"
#import "SuccessInvestVC.h"
@interface InvestUnverifVC ()<UITableViewDelegate,UITableViewDataSource,TTTAttributedLabelDelegate>
{
    NSArray *_titleArray;
    NSArray *_canEditArray;
    NSArray *_placeHodlerArray;
    NSMutableArray *_dataArrary;
}
@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *dataSource;

@property (nonatomic,strong) UIButton *investBtn;

@property (nonatomic,strong) TTTAttributedLabel *infoLb;

@property (nonatomic,strong) AgreeView *bottomAgreeView;

@end

@implementation InvestUnverifVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self configUI];

}
- (void)loadData{
    _titleArray = @[@[],@[@"投资金额",@"到期收益"],@[@"姓名",@"身份证号",@"银行",@"银行卡号"]];
    _canEditArray = @[@[],@[@1,@0],@[@1,@1,@0,@1]];
    _dataArrary = @[@[],@[@"",@""],@[@"",@"",@"",@""]].mutableCopy;
    _placeHodlerArray = @[@[],@[@"100起投,且为50的整数倍",@""],@[@"请输入持卡人姓名",@"请输入身份证号",@"请选择银行",@"请输入银行卡号"]];
}
- (void)configUI{
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.investBtn];
}
- (void)viewDidLayoutSubviews{
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 44, 0));
    }];
    [_investBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(_tableView.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
    
}
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{
    if (label==_infoLb) {
        [self jumpToH5VCByURL:[NSString stringWithFormat:@"%@%@",HOSTURL_FOR_REPORT,@"assetzz/mobileH5/prompt.jsp"]];
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2 &&indexPath.row == 2) {
        BankListVC *bankVC = [[BankListVC alloc]init];
        [self.navigationController pushViewController:bankVC animated:YES];
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        InvestDetailHeadView *headView =  [[[NSBundle mainBundle]loadNibNamed:@"InvestDetailHeadView" owner:nil options:NULL]firstObject];
        
        return headView;
    }else{
        return self.infoLb;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 2) {
        UIView *footerView = [[UIView alloc]init];
        [footerView addSubview:self.bottomAgreeView];
        [_bottomAgreeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(footerView);
            make.height.equalTo(@30);
            make.width.equalTo(@200);
        }];
        return footerView;
    }else{
        return nil;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 150;
    }else if (section == 1) {
        return 10.00;
    }else{
        return 40;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 2) {
        return 40;
    }else{
        return 0.001f;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InvestTableViewCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"InvestTableViewCell" owner:nil options:NULL]firstObject];
    [cell setTitleStr:_titleArray[indexPath.section][indexPath.row] canEditStr:[_canEditArray[indexPath.section][indexPath.row] boolValue] editText:_dataArrary[indexPath.section][indexPath.row] placeHodel:_placeHodlerArray[indexPath.section][indexPath.row]];
    if (indexPath.section!=1) {
        [cell hideRightUnitLb];
    }
    if (indexPath.section == 2&&indexPath.row == 2) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.0f;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 0;
    }else if (section == 1) {
        return 2;
    }else{
        return 4;
    }
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (TTTAttributedLabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [TTTAttributedLabel new];
        _infoLb.frame = CGRectMake(0, 0, KWidth, 35);
        [_infoLb setStlyeByText:@"       银行卡支付 (充值错误码含义)" andLinkText:@"(充值错误码含义)"];
        _infoLb.delegate = self;
    }
    return _infoLb;
}

- (AgreeView *)bottomAgreeView{
    if (!_bottomAgreeView) {
        _bottomAgreeView = [[AgreeView alloc]initwithText:@"我已阅读《中增理财服务协议》" andLinkText:@"《中增理财服务协议》" Selectblock:^{
             [self jumpToH5VCByURL:[NSString stringWithFormat:@"%@%@",HOSTURL_FOR_REPORT,@"assetzz/protocol_service.jsp"]];
        } StateChangeBlock:^(BOOL nowState) {
            
        }];
    }
    return _bottomAgreeView;
}
- (UIButton *)investBtn{
    if (!_investBtn) {
        _investBtn = [[UIButton alloc]init];
        [_investBtn setBackgroundImage:UIImageMake(@"bottombtnbgcolor") forState:UIControlStateNormal];
        [_investBtn setTitle:@"立 即 支 付" forState:UIControlStateNormal];
        [_investBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _investBtn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        [_investBtn bk_addEventHandler:^(id sender) {
//       支付
        } forControlEvents:UIControlEventTouchUpInside];
    }
    return _investBtn;
}

@end
